import os


class ReportPath:

    def __init__(self, report_nm):
        # report_nm = 'hah'
        report_nm = (report_nm.replace(':', '：').replace('*', '').replace('/', '').replace('\\', '').replace('?', '')
                     .replace('"', '').replace('<', '').replace('>', '').replace('|', ''))
        self.file_all_name = report_nm
        if '.' not in self.file_all_name:
            self.file_name = self.file_all_name
            self.file_suffix = ''
        else:
            self.file_name = '.'.join(report_nm.split('.')[:-1])
            self.file_suffix = report_nm.split('.')[-1]
        wd = os.getcwd().replace('\\', '/')
        dir_path = f'{wd}/report'
        self.dir_path =dir_path
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
        self.file_path = self.dir_path + f'/{self.file_all_name}'


class ReportInfo:

    def __init__(self, stock_code, stock_short, file_title, type_=None):
        self.stock_code = stock_code
        self.stock_short = stock_short
        self.report_type = type_
        self.file_title = file_title
        if self.report_type is None:
            if '半' in self.file_title:
                self.report_type = '半年报'
            else:
                self.report_type = '年报'
        self.file_path = ReportPath(f'{self.stock_code}_{self.stock_short}_{self.file_title}.pdf')


if __name__ == '__main__':
    r1 = ReportPath('adsdas.dsada.hahah')
    print(r1.file_all_name)
    print(r1.file_path)
    print(r1.file_name)
    print(r1.file_suffix)
    print(r1.dir_path)
